<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="108px">
      <el-form-item label="日期" prop="checkDate">
        <el-date-picker clearable size="small" style="width: 200px"
                        v-model="queryParams.checkDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        :picker-options="pickerOptions"
                        placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="班级" prop="classId">
        <el-select v-model="queryParams.classId" filterable placeholder="请选择班级" >
          <el-option
            v-for="item in classList"
            :key="item.id"
            :label="item.label"
            :value="item.id"
            size="small">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="幼儿姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>


      </el-form-item>
    </el-form>

    <el-button type="primary"  size="mini" @click="handleExport" >批量修改</el-button>
    <el-button type="info" icon="el-icon-download" size="mini" @click="handleExport" >导出</el-button>
    <el-table v-loading="loading" :data="studentList">

      <!--    <el-table-column type="selection" width="55" align="center" />-->
      <el-table-column label="序号" align="center" width="50">
        <template slot-scope="scope">
          {{scope.$index + (queryParams.pageNum-1)*queryParams.pageSize +1}}
        </template>
      </el-table-column>
      <el-table-column label="检查时间" align="center" prop="checkTime" width="150"/>
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="性别" align="center" prop="studentSex">
        <template slot-scope="scope">
          <!-- <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.studentSex==0?'1':'0'"/> -->
          {{ scope.row.studentSex==0?'女':scope.row.studentSex==1?'男':'未知'}}
        </template>
      </el-table-column>
      <el-table-column label="年龄" align="center" prop="studentAge" />
      <el-table-column label="身高/cm" align="center" prop="height" />
      <el-table-column align="center" label="体重/kg" prop="weight"/>
      <el-table-column align="center" label="体温/°C" prop="temperature"/>
      <el-table-column align="center" label="牙齿" prop="teethStatus">
        <template slot-scope="scope">
          <div v-if="scope.row.teethStatus=='1'" >异常</div>
          <div v-if="scope.row.teethStatus=='0'" >正常</div>
        </template>
      </el-table-column>
      <el-table-column align="center" label="眼睛" prop="eyeStatus">
        <template slot-scope="scope">
          <div v-if="scope.row.eyeStatus=='1'" >异常</div>
          <div v-if="scope.row.eyeStatus=='0'" >正常</div>
          <div v-if="scope.row.eyeStatus=='2'" >未检查</div>
        </template>
      </el-table-column>
      <el-table-column  align="center" label="手部"  prop="handStatus">
        <template slot-scope="scope">
          <div v-if="scope.row.handStatus=='1'" >异常</div>
          <div v-if="scope.row.handStatus=='0'" >正常</div>
          <div v-if="scope.row.handStatus=='2'" >未检查</div>
        </template>
      </el-table-column>
      <el-table-column  align="center" label="口腔"  prop="oralStatus">
        <template slot-scope="scope">
          <div v-if="scope.row.oralStatus=='1'" >异常</div>
          <div v-if="scope.row.oralStatus=='0'" >正常</div>
          <div v-if="scope.row.oralStatus=='2'" >未检查</div>
        </template>
      </el-table-column>
      <el-table-column align="center" label="指甲" prop="nailsStatus">
        <template slot-scope="scope">
          <div v-if="scope.row.nailsStatus=='1'" >过长</div>
          <div v-if="scope.row.nailsStatus=='0'" >正常</div>
        </template>
      </el-table-column>
      <el-table-column  align="center" label="外伤"  prop="traumaStatus">
        <template slot-scope="scope">
          <div v-if="scope.row.traumaStatus=='1'" >异常</div>
          <div v-if="scope.row.traumaStatus=='0'" >正常</div>
          <div v-if="scope.row.traumaStatus=='2'" >未检查</div>
        </template>
      </el-table-column>
      <el-table-column  align="center" label="处理方式"  prop="processingMethod">
        <template slot-scope="scope">
          <div v-if="scope.row.processingMethod=='1'" >送医</div>
          <div v-if="scope.row.processingMethod=='2'" >误报</div>
          <div v-if="scope.row.processingMethod=='3'" >已处理</div>
          <div v-if="scope.row.processingMethod=='4'" >其他</div>
        </template>
      </el-table-column>
       <el-table-column  align="center" label="其他症状"  prop="others">
      </el-table-column>
         <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
           <template slot-scope="scope">
             <el-button
               size="mini"
               type="text"
               icon="el-icon-edit"
               @click="handleUpdate(scope.row)"
             >修改</el-button>
             <el-button
               size="mini"
               type="text"
               icon="el-icon-delete"
               @click="handleDelete(scope.row)"
               v-hasPermi="['base:student:remove']"
             >删除</el-button>
             <el-button
               size="mini"
               type="text"
               icon="el-icon-delete"
               @click="handleUnbind(scope.row)"
             >清除绑定</el-button>
           </template>
         </el-table-column> -->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改毕业管理对话框 -->
    <el-dialog  :close-on-click-modal="false" title="修改" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="身高/cm" prop="height">
          <el-input v-model="form.height" placeholder="请输入身高/cm" />
        </el-form-item>
        <el-form-item label="体重/kg" prop="weight">
          <el-input v-model="form.weight" placeholder="请输入体重/kg" />
        </el-form-item>
        <el-form-item label="体温/°C" prop="temperature">
          <el-input v-model="form.temperature" placeholder="请输入体温/°C" />
        </el-form-item>
        <el-form-item label="牙齿" prop="teethStatus">
          <el-select v-model="form.teethStatus" placeholder="请选择牙齿状况">
            <el-option
              v-for="item in isNormalList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="眼睛" prop="eyeStatus">
          <el-select v-model="form.eyeStatus" placeholder="请选择眼睛状况">
            <el-option
              v-for="item in isExamineList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="手部" prop="handStatus">
          <el-select v-model="form.handStatus" placeholder="请选择手部状况">
            <el-option
              v-for="item in isExamineList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="口腔" prop="oralStatus">
          <el-select v-model="form.oralStatus" placeholder="请选择口腔状况">
            <el-option
              v-for="item in isExamineList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="指甲" prop="nailsStatus">
          <el-select v-model="form.nailsStatus" placeholder="请选择指甲状况">
            <el-option
              v-for="item in nailExamineList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="外伤" prop="traumaStatus">
          <el-select v-model="form.traumaStatus" placeholder="请选择外伤状况">
            <el-option
              v-for="item in isExamineList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="其他症状" prop="others">
          <el-input v-model="form.others" placeholder="请输入其他症状" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>


import {selectClazz} from "@/api/base/clazz";
import {checkStudents,exportAll,updateCheckStatus} from "@/api/base/ill";
import { formatDateOnly} from "@/utils";

export default {
  name: "gzt",
  dicts: ['sys_user_sex'],
  data() {
    return {
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        schoolCode:this.$store.getters.schoolCode,
        checkDate:formatDateOnly(new Date()),
      },
      classList:[],
      studentList:[],
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        },
      },
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        height: [
          { required: true, message: "身高不能为空", trigger: "blur" }
        ],
        weight: [
          { required: true, message: "体重不能为空", trigger: "blur" }
        ],
        temperature: [
          { required: true, message: "体温不能为空", trigger: "blur" }
        ],
        teethStatus: [
          { required: true, message: "牙齿状况不能为空", trigger: "blur" }
        ],
        eyeStatus: [
          { required: true, message: "眼睛状况不能为空", trigger: "blur" }
        ],
        handStatus: [
          { required: true, message: "手部状况不能为空", trigger: "blur" }
        ],
        oralStatus: [
          { required: true, message: "口腔状况不能为空", trigger: "blur" }
        ],
        nailsStatus: [
          { required: true, message: "指甲状况不能为空", trigger: "blur" }
        ],
        traumaStatus: [
          { required: true, message: "外伤状况不能为空", trigger: "blur" }
        ],
      },
      isNormalList:[
        {
          value: '0',
          label: '正常'
        },
        {
          value: '1',
          label: '异常'
        }
      ],//异常,正常
      isExamineList:[
        {
          value: '0',
          label: '正常'
        },
        {
          value: '1',
          label: '异常'
        },
        {
          value:'2',
          label:'未检查'
        }
      ],//异常,正常,未检查
      nailExamineList:[
        {
          value: '0',
          label: '正常'
        },
        {
          value: '1',
          label: '过长'
        }
      ],//指甲状况
    };
  },
  created() {
    //班级
    this.getQueryClazzList();
    this.getList()
  },
  methods: {
    // 修改
    handleUpdate(row){
      this.open = true
      this.form = row
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
            updateCheckStatus(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
        }
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
    },
    // 导出
    handleExport() {
      this.handleQuery();
      exportAll(this.queryParams).then(response => {
        this.download(response.msg);
      })
    },
    /** 查询学生列表 */
    async getList() {
      try {
        this.loading = true;
        const data=await checkStudents(this.queryParams);
        console.log(data)
        this.studentList = data.rows;
        this.total = data.total;
        this.loading = false;
      }catch (e) {
        console.log(e)
      }

    },
    /** 查询班级列表 */
    async getQueryClazzList() {
      try{
        this.loading = true;
        const {rows}=await selectClazz();
        this.classList=rows.map(item=>{
          return {
            id:item.id,
            label:item.title,
          }
        })
        this.loading = false;
      }catch (e) {
        console.log(e)
      }
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
  }
};
</script>
